date).
+Side note: The xvd* devices
+---------------------------
+
+The examples in this document make frequent use of the xvd* device nodes for
+representing virtual block devices. It is not a requirement to use these with
+Xen, since VBDs can be mapped to any IDE or SCSI device node in the system.
+Changing the the references to xvd* nodes in the examples below to refer to
+some unused hd* or sd* node would also be valid.
+
+They can be useful when accessing VBDs from dom0, since binding VBDs to xvd*
+devices under will avoid clashes with real IDE or SCSI drives.
+
+There is a shell script provided in tools/misc/xen-mkdevnodes to create these
+nodes. Specify on the command line the directory that the nodes should be
+placed under (e.g. /dev):
+
+> cd {root of Xen source tree}/tools/misc/
+> ./xen-mkdevnodes /dev
+
+
Dynamically Registering VBDs
----------------------------
(Note that you need to use quotes here, since config files are really small
Python scripts.)
-To specify the mapping on the commandline, you'd use the -d switch and supply
+To specify the mapping on the command line, you'd use the -d switch and supply
the triple as the argument, e.g.:
> xc_dom_create.py [other arguments] -d phy:hdc,/dev/whatever,r
FROM vdisks NATURAL JOIN vdisk_extents
NATURAL JOIN vdisk_part
WHERE expires AND expiry_time <= datetime('now')
- ORDER BY expiry_time asc, vdisk_extent_no desc
+ ORDER BY expiry_time ASC, vdisk_extent_no DESC
""") # aims to reuse the last extents
# from the longest-expired disks first
if not count:
cx.close()
- return -1
+ return None
cu.execute("SELECT size from vdisks WHERE vdisk_id = " + id)
real_size, = cu.fetchone()
NATURAL JOIN vdisk_part
WHERE vdisk_extents.vdisk_id = """ + id
+ + " ORDER BY vdisk_extents.vdisk_extent_no ASC"
)
extent_tuples = cu.fetchall()
FROM vdisks NATURAL JOIN vdisk_extents
NATURAL JOIN vdisk_part
WHERE expires AND expiry_time <= datetime('now')
- ORDER BY expiry_time asc, vdisk_extent_no desc
+ ORDER BY expiry_time ASC, vdisk_extent_no DESC
""") # aims to reuse the last extents
# from the longest-expired disks first
extents = vd_lookup(vdisk_id)
- if extents < 0:
+ if not extents:
return -1
file_idx = 0 # index into source file, in sectors
returns [string] : vdisk ID for the destination vdisk
"""
- size_sectors = os.stat(filename).st_size / 512
+ size_bytes = os.stat(filename).st_size
- vdisk_id = vd_create(size_sectors / ( 2 * 1024 ),expiry)
+ (size_mb,leftover) = divmod(size_bytes,1048580) # size in megabytes
+ if leftover > 0: size_mb += 1 # round up if not an exact number of MB
+
+ vdisk_id = vd_create(size_mb, expiry)
if vdisk_id < 0:
return -1
cu.execute("""SELECT partition, extent_size, part_extent_no
FROM vdisk_part NATURAL JOIN vdisk_extents
WHERE vdisk_id = """ + vdisk_id + """
- ORDER BY vdisk_extent_no""")
+ ORDER BY vdisk_extent_no ASC""")
extents = cu.fetchall()
+ size_sectors = size_mb * 2048 # for feeding to dd
+
file_idx = 0 # index into source file, in sectors
def write_extent_to_vd((partition, extent_size, part_extent_no),
+ " count=" + str(min(extent_size, size_sectors - file_idx))
+ " > /dev/null")
- return file_idx + extent_size
+ return extent_size
for i in extents:
file_idx += write_extent_to_vd(i, file_idx, filename)